package com.lb.jwitter.action;


import java.util.Collection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import java.util.Map; 
import org.springframework.test.context.ContextConfiguration; 
import com.lb.jwitter.service.TblQuyenChiTietService; 
import com.lb.jwitter.service.TblTaiKhoan; 
import com.opensymphony.xwork2.ActionContext; 
import com.lb.jwitter.util.ApplicationContextProvider; 
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.opensymphony.xwork2.Action; 
import com.lb.jwitter.service.TblCTDTKhoiNganhMonHoc;
import com.lb.jwitter.service.TblCTDTKhoiNganhMonHocService;
import com.lb.jwitter.service.TblCTDTKhoiNganh;
import com.lb.jwitter.service.TblCTDTKhoiNganhService;

import com.lb.jwitter.service.TblCTDTMonHoc;
import com.lb.jwitter.service.TblCTDTMonHocService;

 /** 
 * @author QUOCVIET  
 * 
 */ 


@ContextConfiguration(locations="classpath:beans.xml") 
public class TblCTDTKhoiNganhtblCTDTKhoiNganhMonHocEditFormAction{
    private int id; 
    public void setId(int id) {
       this.id = id;
 }

    public int getId() {
       return id;
 }

    private TblCTDTKhoiNganhMonHoc tblCTDTKhoiNganhMonHoc; 
    public TblCTDTKhoiNganhMonHoc getTblCTDTKhoiNganhMonHoc() { 
        return tblCTDTKhoiNganhMonHoc; 
    } 
    private TblCTDTKhoiNganh tblCTDTKhoiNganh; 
    public TblCTDTKhoiNganh getTblCTDTKhoiNganh() { 
        return tblCTDTKhoiNganh; 
    } 
    private Collection<TblCTDTKhoiNganhMonHoc> tblCTDTKhoiNganhMonHocs; 
    public Collection<TblCTDTKhoiNganhMonHoc>  getTblCTDTKhoiNganhMonHocs() {
         return tblCTDTKhoiNganhMonHocs; 
      } 

    private TblCTDTKhoiNganhMonHocService tblCTDTKhoiNganhMonHocService; 

    private Collection<TblCTDTKhoiNganh> tblCTDTKhoiNganhs; 
    public Collection<TblCTDTKhoiNganh>  getTblCTDTKhoiNganhs(){ 
              return tblCTDTKhoiNganhs; 
     } 

    private TblCTDTKhoiNganhService tblCTDTKhoiNganhService; 

    private Collection<TblCTDTMonHoc> tblCTDTMonHocs; 
    public Collection<TblCTDTMonHoc>  getTblCTDTMonHocs(){ 
              return tblCTDTMonHocs; 
     } 

    private TblCTDTMonHocService tblCTDTMonHocService; 

  private TblTaiKhoan taiKhoanDangNhap; 
 public TblTaiKhoan getTaiKhoanDangNhap() { 
     return taiKhoanDangNhap; 
 } 
 public void setTaiKhoanDangNhap(TblTaiKhoan taiKhoanDangNhap) { 
     this.taiKhoanDangNhap = taiKhoanDangNhap; 
 } 
 private TblQuyenChiTietService tblQuyenChiTietService;
	 @Autowired // Injected by Spring 
     ApplicationContextProvider contextProvider; 
    public String execute() throws Exception 
   { 
    try{ 
     Map session = ActionContext.getContext().getSession();
     taiKhoanDangNhap =  (TblTaiKhoan) session.get("taiKhoan");
     if( taiKhoanDangNhap == null) return "noprivilege";
    ApplicationContext context = ApplicationContextProvider.getApplicationContext(); 
    tblQuyenChiTietService = (TblQuyenChiTietService) context.getBean("tbl_Quyen_ChiTietClient"); 
    if(!tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_CTDT_KhoiNganh_MonHoc", "sua")){ 
        return "noprivilege"; 
    }        tblCTDTKhoiNganhMonHocService = (TblCTDTKhoiNganhMonHocService) context.getBean("tbl_CTDT_KhoiNganh_MonHocClient"); 
        tblCTDTKhoiNganhService = (TblCTDTKhoiNganhService) context.getBean("tbl_CTDT_KhoiNganhClient"); 

        tblCTDTMonHocService = (TblCTDTMonHocService) context.getBean("tbl_CTDT_MonHocClient"); 

        tblCTDTKhoiNganhMonHoc = tblCTDTKhoiNganhMonHocService.gettblCTDTKhoiNganhMonHoc(new Long(id)); 
        tblCTDTKhoiNganh = tblCTDTKhoiNganhMonHoc.getKhoiNganhId(); 
        tblCTDTMonHocs = tblCTDTMonHocService.findAlltblCTDTMonHoc(0, 0);

        return Action.SUCCESS; 
      } 
      catch(Exception e){ 
      System.out.println("Loi EditForm tbl_CTDT_KhoiNganh_MonHoc Action"); 
     e.printStackTrace(); 
    return Action.ERROR; 
 } 
 } 
 } 
 
